package com.yiqi.liebang.feature.home.view.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.RatingBar;
import com.yiqi.liebang.entity.bo.MenuBo;
import com.yiqi.liebang.entity.bo.QuestionBo;

import java.util.List;

public class QuestionAdapter extends BaseQuickAdapter<QuestionBo, BaseViewHolder> {
    public QuestionAdapter() {
        super(R.layout.item_home_question);
    }

    @Override
    protected void convert(BaseViewHolder helper, QuestionBo item) {
        helper.setText(R.id.tv_user_question_content, item.getQuizcontent())
                .setText(R.id.tv_user_question_help, item.getUserAccountFormMap() == null ? "" : "帮助过" + item.getUserAccountFormMap().getHelpNum() + "人")
                .setText(R.id.tv_user_question_name, item.getUserAccountFormMap() == null ? "" : item.getUserAccountFormMap().getUserName() + "")
                .setText(R.id.tv_user_question_position, item.getUserAccountFormMap() == null ? "" :
                        (TextUtils.isEmpty(item.getUserAccountFormMap().getPosition()) ? "" : item.getUserAccountFormMap().getPosition()))
                .setVisible(R.id.iv_user_position, item.getUserAccountFormMap() == null ? false : item.getUserAccountFormMap().getIsOccupation() == 1 ? true : false)
                .setText(R.id.tv_user_question_time, item.getChargestate() == 0 ? "限时免费" : "1元")
                .setTextColor(R.id.tv_user_question_time, item.getChargestate() == 0 ? AM.res().getColor(R.color.color_fe_70_1b) : AM.res().getColor(R.color.primary_highlight))
                .addOnClickListener(R.id.iv_user_question_head)
                .addOnClickListener(R.id.iv_user_position)
                .addOnClickListener(R.id.iv_user_certification)
        ;

        if (!TextUtils.isEmpty(item.getUserAccountFormMap().getCompany()) || !TextUtils.isEmpty(item.getUserAccountFormMap().getPosition())) {
            helper.getView(R.id.view_line).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.view_line).setVisibility(View.GONE);
        }

        TextView textView = helper.getView(R.id.tv_user_question_time);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, item.getChargestate() == 0 ? 12 : 15);

        if (item.getUserAccountFormMap() == null ? false : item.getUserAccountFormMap().getIsBasic() == 1) {
            helper.getView(R.id.iv_user_certification).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.iv_user_certification).setVisibility(View.GONE);
        }
        RatingBar ratingBar = helper.getView(R.id.rb_user_question_star);
        if (item.getStartLevel() > 0) {
            ratingBar.setStar(item.getStartLevel());
        }

        AM.image().bindToCircleObject(item.getUserAccountFormMap() == null ? "" : item.getUserAccountFormMap().getUserHead(), helper.getView(R.id.iv_user_question_head));
    }
}
